package site.syksy.qingzhou.security.authentication;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import site.syksy.qingzhou.security.domain.GeneralLoginVO;

import java.util.Collection;

/**
 * @author Raspberry
 * 身份令牌
 */
public class GeneralAuthenticationToken extends AbstractAuthenticationToken {

    private GeneralLoginVO generalLoginVO;

    public GeneralAuthenticationToken(GeneralLoginVO generalLoginVO) {
        super(null);
        this.generalLoginVO = generalLoginVO;
        setAuthenticated(false);
    }

    public GeneralAuthenticationToken(Collection<? extends GrantedAuthority> authorities, GeneralLoginVO generalLoginVO) {
        super(authorities);
        this.generalLoginVO = generalLoginVO;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return generalLoginVO;
    }

    @Override
    public Object getPrincipal() {
        return generalLoginVO.getUsername();
    }
}
